﻿<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <title>任务信息</title>
</head>

<body>

    <div class="page-container">
        <div class="searcharea">
            <div class="st">
                <span class="sn">任务信息</span>
                <span class="idesc">查看某一个任务的执行记录，可以了解系统是否正常运作！</span>
            </div>
            <form id="formsearch">
                <div class="searchbox">
                    <input type="button" class="btnstyle btnadd islocal" value="新增"
                        onclick="_showedit('新增单项','view.html','0','80%','80%');" />

                    <span>关键字：</span>
                    <input type="text" class="inputword" style="width:250px" placeholder="" name="word" value="">

                    <span>状态：</span>
                    <select name="state">
                        <option value="-1">不限定</option>
                        <option value="1" selected>运行中</option>
                        <option value="0">禁用的</option>
                    </select>

                    <span>开始时间:</span><input type="text" maxlength="19" class="inputword" value=""
                        placeholder="格式:yyyy-MM-dd HH:mm:ss" name="sdate" />

                    <span>结束时间:</span><input type="text" maxlength="19" class="inputword" value=""
                        placeholder="格式:yyyy-MM-dd HH:mm:ss" name="edate" />


                    <input type="button" class="btnsearch" onclick="_readpagedata(1);" value="查询">
                </div>
            </form>


            <a class="ataprefresh" style="line-height:1.6em;margin-top:3px"
                href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>

        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                <thead>
                    <tr class="text-c">
                        <th width="60">ID</th>
                        <th width="150">运行组</th>
                        <th width="150">名称</th>
                        <th>程序集</th>
                        <th width="160">开启日期</th>
                        <th width="160">到期日期</th>
                        <th>时间规则</th>
                        <th width="80">启用</th>
                        <th width="150" class="islocal">编辑</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <div id="pagenumarea" class="pagenumarea"></div>
    </div>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <!-- <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> -->
    <script src="../lib/api.js"></script>
    <link href="../lib/page.min.css" rel="stylesheet" />
    <script src="../lib/page.min.js"></script>

    <script>
        var pageobject = null;
        var isselect = false;
        function _showpagedata(datas) {
            $("table").find("tbody").empty();
            var hstr = "";
            for (var k = 0; k < datas.length; k++) {
                var item = datas[k];
                var htmlStr = '<tr class="text-c">';
                htmlStr += '<td>' + item.id + '</td>';
                htmlStr += '<td>' + item.groups + '</td>';
                htmlStr += '<td>' + item.name + '</td>';
                htmlStr += '<td>' + item.assembly + '</td>';
                htmlStr += '<td>' + item.startDate + '</td>';
                htmlStr += '<td>' + item.endDate + '</td>';

                if (item.taskType == 3) {
                    htmlStr += '<td>每隔' + item.tickRegex + '</td>';
                } else if (item.taskType == 2) {
                    htmlStr += '<td>逢点' + item.tickRegex + '</td>';
                } else {
                    htmlStr += '<td>' + item.tickRegex + '</td>';
                }
                if (item.isEnable) {
                    htmlStr += '<td><input type="checkbox" class="mui-switch mui-switch-anim" dataid="' + item.id + '" checked></td>';
                } else {
                    htmlStr += '<td><input type="checkbox" class="mui-switch mui-switch-anim" dataid="' + item.id + '" ></td>';
                }
                htmlStr += '<td><a href="javascript:;" onclick="tap_test(this)" dataid="'+item.id+'">直接调用</a><a title="编辑" href="javascript:;" onclick="_showedit(\'编辑\',\'view.html\',\'' + item.id + '\',\'80%\',\'80%\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a></td>'
                htmlStr += '</tr>';
                hstr += htmlStr;
            }
            $("table").find("tbody").append(hstr);
        }

        /*
        *选择一个对象 
        */
        function _functionSelect(elc) {
            var dataid = parseInt($(elc).attr("dataid"));
            var info = { id: dataid, name: $(elc).attr("datastr") };
            window.parent.postMessage({ type: 'appinfo', data: info });
            //关闭自己
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);  // 关闭layer
        }
        $(window).ready(function () {
            var gruidstr = _apigetquery("guid");
            if (gruidstr != null) {
                $(".inputword").val(gruidstr);
            }
            _readpagedata(1);
            $(".inputword").keyup(function (event) {
                if (event.keyCode == 13) {
                    _readpagedata(1);
                }
            });

            $(".table").on("change", "[type=checkbox]", function (e) {
                var checkval = $(this).prop("checked");
                var _that = $(this);
                console.log("点击，获取到" + checkval);
                var dataid = $(this).attr("dataid");
                layer.confirm('确定修改状态么？', { btn: ["确定", "取消"] }, function (index) {
                    _apipost("/api/task/taskInfo/" + dataid + "/updateState?state=" + checkval, true, "", function (code, obj) {
                        layer.close(index);
                        if (code != 200) {
                            _that.prop("checked", !checkval);
                            console.log("修改为" + !checkval + "值为" + checkval);
                        }
                    });
                }, function () {
                    _that.prop("checked", !checkval);
                    console.log("取消动作，执行" + !checkval);
                });
            })
        });

        function _readpagedata(page) {
            // var inputword = $(".inputword").val();
            if(page==1){
                $("#pagenumarea").html('');
            }
            var _info = $("#formsearch").parseForm();
            _info.page = page;
            _info.size = 30;
            if(_info.sdate.length==0){ delete _info.sdate;}
            if(_info.edate.length==0){ delete _info.edate;}
            _apiquery("/api/task/taskInfo/page", true, _info, function (code, obj) {
                if (code == 200) {
                    var datas = obj.items;
                    _showpagedata(datas);
                    if (pageobject == null || page == 1) {
                        pageobject = new Page({
                            el: '#pagenumarea',
                            nums: obj.totalCount,//总数
                            counts: _info.size,//每页大小
                            defaultPage: 1,
                            showHeadFoot: false, // 显示首页尾页
                            head: '首', // 更改首页文字
                            foot: '尾', // 更改尾页文字
                            jumpToOrder: true, // 跳转到指定页
                            showNowAndAll: true, // 当前页/共几页
                            prev: "上一页",
                            next: "下一页",
                            clickEvent: function (currectPage, _this) {
                                _readpagedata(currectPage);
                            }
                        });
                    }
                }
            });
        }
        function _tosearch(word) {
            // $(".inputword").val("");
            $(".inputword").val(word);
            setTimeout(() => {
                _readpagedata(1);
            }, 300);
        }

        /**
         * 尝试调用任务
         **/ 
        function tap_test(elc){
            var _dataid =$(elc).attr('dataid');
            layer.confirm('确定调用这个任务么，会基于系统的逻辑，向对应节点发起请求，基于配置可能会重试,点击将发起调用！', { btn: ["确定", "取消"] }, function (index) {
                    _apipost("/api/task/taskInfo/" + _dataid + "/test", true, "", function (code, obj) {
                        layer.close(index);
                        layer.msg(obj);
                    });
                }, function () {
                });
        }

    </script>
</body>
</html>